# encoding=utf8
import sys
reload(sys)
sys.setdefaultencoding('utf8')

class FT_07b3:
    
    Data_array1 = [["发动机起动机模式","2"],["实际添蓝喷射量","8"],["进气氮氧测量值","4"],["进气氧含量（或DOC前氧）","4"],["排气氮氧测量值","4"],["排气氧含量（或DOC后氧）","4"],["泵端添蓝压力","4"],["泵转速（如使用）","4"],["催化剂上游温度","4"],["催化剂下游温度","4"],["泵工作状态","2"],["排气背压（DPF/POC)","2"],["排气温度（DPF/POC)","4"],["进气压力（DPF）","2"],["进气温度（DPF/POC）","4"],["DOC前氧","4"],["DOC后氧","4"]]
    
    Data_array2 = [["发动机转速","4"],["进气歧管压力","2"],["油门踏板位置","2"],["车速","4"],["进气歧管温度","2"],["发动机进气温度","4"],["累计里程","8"],["发动机扭矩模式","2"],["发动机实际扭矩百分比","2"],["发动机参考扭矩","4"],["发动机累计工作时间","8"],["发动机累计运转转数","8"],["发动机累计燃油消耗量","8"],["SCR催化剂罐液位","2"],["SCR催化剂罐温度","2"],["载体压差（DPF/POC）","4"],["喷油量","4"],["脚刹","2"],["手刹","2"],["机油压力","2"],["机油温度","4"],["电池电压","4"],["瞬时燃油消耗率","4"],["摩擦力扭矩","2"],["纬度","8"],["经度","8"]]
    analysis07b3Length = [2, 1, 6, 0, 0]
    analysis07b3 = ["自定义消息体长度:", "数据组上报方式:", "采集时间:", "数据组1：", "数据组2："]


    protocolStr = ''
    messageLength = []  # 自定义消息体长度
    dataarrayRepMode = '' #数据组上报方式
    collectTime = '' #采集时间
    data_g_str1 = '' #数据组1
    result = []

    def LogicAisle(self, protocol, header):
        self.result = header
        self.protocolStr = protocol
        self.Init()
        self.result.append(self.analysis07b3[0] + self.messageLength + '\n')    # 自定义消息体长度
        self.result.append(self.analysis07b3[1] + self.dataarrayRepMode + '\n')  # 数据组上报方式
        self.result.append(self.analysis07b3[2] + self.collectTime + '\n')   # 采集时间
        if (self.dataarrayRepMode == '00'):
            #数据组
            self.data_g_str1 = self.protocolStr[18:82]
            self.data_g_str2 = self.protocolStr[82:]
            flag1 = self.Data_array1
            flag2 = self.Data_array2
            startPoint1=0
            startPoint2=0
            self.result.append(self.analysis07b3[3])
            for i in range(len(flag1)):
                print "i",i
                print "len(flag1)",(len(flag1))
                dataarrayLen = flag1[i][1]
                print "dataarrayLen",dataarrayLen
                print "startPoint1hhhhhh",startPoint1
                endPoint = startPoint1+int(dataarrayLen)
                print "endPoint",endPoint
                tmpdata = self.data_g_str1[startPoint1:endPoint]
                print "tmpdata",tmpdata
                print "flag1[i][0]",(flag1[i][0])
                self.result.append( flag1[i][0] + tmpdata + '\n')
                startPoint1 = endPoint
                print "startPoint1lllllll",startPoint1
            self.result.append(self.analysis07b3[4])
            for i in range(len(flag2)):
                dataarrayLen = flag2[i][1]
                endPoint = startPoint2+int(dataarrayLen)
                tmpdata = self.data_g_str2[startPoint2:endPoint]
                self.result.append( flag2[i][0] + tmpdata + '\n')
                startPoint2 = endPoint
        else:
            
            self.data_g_str1 = self.protocolStr[18:82]
            flag1 = self.Data_array1
            startPoint1=0
            for i in range(len(flag1)):
                dataarrayLen = flag1[i][1]
                endPoint = startPoint1+int(dataarrayLen)
                tmpdata = self.data_g_str1[startPoint1:endPoint]
                self.result.append(self.analysis07b3[3] + flag1[i][0] + tmpdata + '\n')
                startPoint1 = endPoint
            
    def Init(self):
        self.setMessageLength()
        self.setDataarrayRepMode()
        self.setCollectTime()

    def setMessageLength(self):
        self.messageLength = self.protocolStr[0:4]
        print"setMessageLength"
    def setDataarrayRepMode(self):
        self.dataarrayRepMode = self.protocolStr[4:6]
        print"setDataarrayRepMode"
    def setCollectTime(self):
        self.collectTime = self.protocolStr[6:18]
        print"setCollectTime"
